package com.corgi.mybatis.base.json;

import com.corgi.mybatis.util.AesUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

/**
 * @title: JacksonStringAesEncryptSerializer
 * @description:
 * @author: dengmiao
 * @create: 2019-10-29 13:14
 **/
public class JacksonStringAesEncryptSerializer extends JsonSerializer<String> {

    private final static String AES_KEY = "1234567890123456";

    private final static String AES_IV = "0000000000000000";

    @Override
    public void serialize(String s, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String encrypt = AesUtil.encryptCBC(s, AES_KEY, AES_IV);
        // System.out.println(encrypt);
        jsonGenerator.writeString(encrypt);
    }
}
